<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <meta name="description" content="种一棵树，让它在时间的深度和长度中慢慢生长 | Mapo，Node.js & React.js Developer | 与君共勉，现在就是最好的时机">
    <meta name="keywords"  content="Mapo, Mapo博客, Mapo Blog, 博客, 个人网站, 互联网, Web, JavaScript, 前端, Node.js">
    <meta name="theme-color" content="#000000">
    
    <!-- Open Graph -->
    <meta property="og:title" content="同时部署Jekyll到Github和Coding的Pages服务上 - Mapo的博客 | Mapo Blog">
    
    <meta property="og:type" content="article">
    <meta property="og:description" content="
  记录了我的博客部署过程，非常感谢Github、Coding提供的Pages服务，Gitalk提供的开源评论方案，Jekyll提供的博客方案。

">
    
    <meta property="article:published_time" content="2019-04-06T00:25:00Z">
    
    
    <meta property="article:author" content="Mapo">
    
    
    <meta property="article:tag" content="Jekyll">
    
    <meta property="article:tag" content="Pages">
    
    <meta property="article:tag" content="Coding">
    
    <meta property="article:tag" content="Github">
    
    <meta property="article:tag" content="Gitalk">
    
    <meta property="article:tag" content="TravisCI">
    
    <meta property="article:tag" content="记录">
    
    
    <meta property="og:image" content="https://mapo.io/img/avatar-mapo-ny.png">
    <meta property="og:url" content="https://mapo.io/2019/04/06/how-to-depoly-jekyll/">
    <meta property="og:site_name" content="Mapo的博客 | Mapo Blog">
    
    <title>同时部署Jekyll到Github和Coding的Pages服务上 - Mapo的博客 | Mapo Blog</title>

    <!-- Web App Manifest -->
    <link rel="manifest" href="/pwa/manifest.json">

    <!-- Favicon -->
    <link rel="shortcut icon" href="/img/favicon.ico">
    
    <!-- Canonical URL -->
    <link rel="canonical" href="https://mapo.io/2019/04/06/how-to-depoly-jekyll/">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/hux-blog.min.css">

    <!-- Custom Fonts -->
    <!-- <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> -->
    <!-- Hux change font-awesome CDN to qiniu -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- ga & ba script hoook -->
    <script></script>
</head>


<!-- hack iOS CSS :active style -->
<body ontouchstart="">

    <!-- Navigation -->

<nav class="navbar navbar-default navbar-custom navbar-fixed-top">

    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Mapo</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>
                    
                    
                    
                    
                    <li>
                        <a href="/about/">About</a>
                    </li>
                    
                    
                    
                    <li>
                        <a href="/archive/">Archive</a>
                    </li>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </ul>
            </div>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    var __HuxNav__ = {
        close: function(){
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        },
        open: function(){
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }

    // Bind Event
    $toggle.addEventListener('click', function(e){
        if ($navbar.className.indexOf('in') > 0) {
            __HuxNav__.close()
        }else{
            __HuxNav__.open()
        }
    })

    /**
     * Since Fastclick is used to delegate 'touchstart' globally
     * to hack 300ms delay in iOS by performing a fake 'click',
     * Using 'e.stopPropagation' to stop 'touchstart' event from 
     * $toggle/$collapse will break global delegation.
     * 
     * Instead, we use a 'e.target' filter to prevent handler
     * added to document close HuxNav.  
     *
     * Also, we use 'click' instead of 'touchstart' as compromise
     */
    document.addEventListener('click', function(e){
        if(e.target == $toggle) return;
        if(e.target.className == 'icon-bar') return;
        __HuxNav__.close();
    })
</script>


    <!-- Image to hack wechat -->
<!-- <img src="/img/icon_wechat.png" width="0" height="0"> -->
<!-- <img src="/img/blue.png" width="0" height="0"> -->

<!-- Post Header -->



<style type="text/css">
    header.intro-header{
        position: relative;
        background-image: url('/img/blue.png');
        background: ;
    }

    
</style>

<header class="intro-header" >

    <div class="header-mask"></div>
    
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <div class="tags">
                        
                        <a class="tag" href="/archive/?tag=Jekyll" title="Jekyll">Jekyll</a>
                        
                        <a class="tag" href="/archive/?tag=Pages" title="Pages">Pages</a>
                        
                        <a class="tag" href="/archive/?tag=Coding" title="Coding">Coding</a>
                        
                        <a class="tag" href="/archive/?tag=Github" title="Github">Github</a>
                        
                        <a class="tag" href="/archive/?tag=Gitalk" title="Gitalk">Gitalk</a>
                        
                        <a class="tag" href="/archive/?tag=TravisCI" title="TravisCI">TravisCI</a>
                        
                        <a class="tag" href="/archive/?tag=%E8%AE%B0%E5%BD%95" title="记录">记录</a>
                        
                    </div>
                    <h1>同时部署Jekyll到Github和Coding的Pages服务上</h1>
                    
                    <h2 class="subheading">同时部署多个节点，加速国内访问</h2>
                    <span class="meta">Posted by Mapo on April 6, 2019</span>
                </div>
            </div>
        </div>
    </div>
</header>






<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

    <!-- Post Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

                <!-- Multi-Lingual -->
                

				<blockquote>
  <p>记录了我的博客部署过程，非常感谢<a href="https://github.com">Github</a>、<a href="https://coding.net">Coding</a>提供的Pages服务，<a href="https://github.com/gitalk/gitalk">Gitalk</a>提供的开源评论方案，<a href="https://jekyllrb.com/">Jekyll</a>提供的博客方案。</p>
</blockquote>

<h2 id="准备工作">准备工作</h2>
<p>在部署Jekyll之前需要准备一些小东西。</p>
<ul>
  <li>一个Github账号</li>
  <li>一个Coding或者Gitee账号</li>
  <li>一个简单好记的域名（实话，io域名还是有点贵的，top域名最便宜。主要是我抢到了四位字母的域名实在是不舍得放弃）</li>
  <li>阿里云或者腾讯云账号</li>
  <li>会使用Google或者Baidu解决问题</li>
</ul>

<p>最后一点很重要，如果不会搜索的话，建议直接直接使用博客园发布文章。不要来折腾这个玩意，会后悔的。</p>

<h2 id="配置jekyll">配置Jekyll</h2>
<blockquote>
  <p>官方Jekyll文档直达：<a href="https://jekyllrb.com/docs/">英文原版文档</a>、<a href="https://jekyllcn.com/docs/home/">中文文档</a></p>
</blockquote>

<blockquote>
  <p>以下是我的博客部署过程，非常简单。本博客的主题是出自<a href="http://huangxuan.me/">Hux</a>的博客</p>
</blockquote>

<blockquote>
  <p>如果你不想去重新配置一个博客，可以直接克隆我的<a href="https://github.com/mapoio/mapoio.github.io">博客</a>，然后直接跳转到<a href="#config">修改_config.yml配置文件</a></p>
</blockquote>

<h3 id="克隆一个博客仓库">克隆一个博客仓库</h3>
<p>可以选择任意一个博客仓库去克隆，然后就可以直接开始写自己的内容了，但是为了后面同时部署方便快捷，我们需要做一点操作。</p>
<ol>
  <li>从Github中下载一个Jekyll博客，例如<a href="https://github.com/Huxpro/huxpro.github.io/archive/master.zip">Hux</a>的博客，点击链接直接下载</li>
  <li>解压<code class="language-plaintext highlighter-rouge">master.zip</code>到<code class="language-plaintext highlighter-rouge">blog</code>文件夹</li>
  <li>在Github中新建一个<code class="language-plaintext highlighter-rouge">你的用户名.github.io</code>的仓库，此处我的仓库名称为<code class="language-plaintext highlighter-rouge">mapoio.github.io</code></li>
  <li>运行如下命令完成git仓库初始化</li>
</ol>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
</pre></td><td class="rouge-code"><pre>git init
git remote add origin git@github.com:mapoio/mapoio.github.io.git
git add <span class="nb">.</span>
git commit <span class="nt">-m</span> <span class="s2">"初始化博客"</span>
git push <span class="nt">-u</span> origin <span class="nb">source</span>
</pre></td></tr></tbody></table></code></pre></div></div>

<blockquote>
  <p>注意： 推送分支直接推送到了远程的<code class="language-plaintext highlighter-rouge">source</code>分支上，不是<code class="language-plaintext highlighter-rouge">master</code>。<code class="language-plaintext highlighter-rouge">master</code>分支将用来部署Pages服务，<code class="language-plaintext highlighter-rouge">source</code>将会是我们的写作分支。</p>
</blockquote>

<div id="config"></div>
<h3 id="修改_configyml配置文件">修改_config.yml配置文件</h3>
<p>_config.yml中包含了网站的所有配置文件，里面包含了注释内容，修改有些注意事项。</p>
<ol>
  <li>务必修改<code class="language-plaintext highlighter-rouge">Site settings</code>设置，这将关系到生成的静态文件，作者</li>
  <li>评论可以使用Disqus、Gitalk、Netease，推荐使用Gitalk，无需备案即可开启评论</li>
  <li>修改<code class="language-plaintext highlighter-rouge">Sidebar settings</code>个人展示信息</li>
</ol>

<p>推荐设置资料：</p>
<ul>
  <li><a href="https://github.com/gitalk/gitalk">Gitalk设置指南</a></li>
  <li><a href="https://github.com/Huxpro/huxpro.github.io">Hux</a></li>
</ul>

<h2 id="部署jekyll到多个服务">部署Jekyll到多个服务</h2>
<blockquote>
  <p>部署方面配置稍微复杂一点</p>
</blockquote>

<h3 id="部署到github-pages">部署到Github Pages</h3>
<p>如果使用Github的默认功能直接去生成Pages，不太好操作，无法直接部署到多个服务节点。所以这里使用TravisCI去部署页面，实现更灵活的方式部署。<br />
这里直接贴出重要脚本</p>
<div class="language-yml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="rouge-code"><pre><span class="c1"># .travis.yml ci配置脚本</span>
<span class="na">language</span><span class="pi">:</span> <span class="s">ruby</span>
<span class="na">rvm</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">2.3.3</span>
<span class="c1"># 设置只监听哪个分支</span>
<span class="na">branches</span><span class="pi">:</span>
  <span class="na">only</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">source</span>
<span class="c1"># 缓存，可以节省集成的时间</span>
<span class="na">cache</span><span class="pi">:</span>
  <span class="na">apt</span><span class="pi">:</span> <span class="no">true</span>
  <span class="na">gem</span><span class="pi">:</span> <span class="no">true</span>
  <span class="na">directories</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">node_modules</span>
<span class="na">before_install</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">git config --global user.name "mapoio"</span>
  <span class="pi">-</span> <span class="s">git config --global user.email "one@mapo.io"</span>
  <span class="pi">-</span> <span class="s">export TZ='Asia/Shanghai'</span>
  <span class="pi">-</span> <span class="s">chmod +x _travis.sh</span>
<span class="na">install</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">gem install jekyll</span>
  <span class="pi">-</span> <span class="s">gem install jekyll-paginate</span>
<span class="na">script</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">jekyll build</span>
<span class="na">after_success</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">./_travis.sh</span>

<span class="na">env</span><span class="pi">:</span>
 <span class="na">global</span><span class="pi">:</span>
   <span class="c1"># 修改为自己Github用户名</span>
   <span class="pi">-</span> <span class="na">GH_USER_NAME</span><span class="pi">:</span> <span class="s">mapoio</span>
   <span class="c1"># 修改为自己Github仓库地址</span>
   <span class="pi">-</span> <span class="na">GH_REF</span><span class="pi">:</span> <span class="s">github.com/mapoio/mapoio.github.io.git</span>
</pre></td></tr></tbody></table></code></pre></div></div>

<p>部署脚本<code class="language-plaintext highlighter-rouge">_travis.sh</code></p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="rouge-code"><pre><span class="c">#!/bin/bash</span>

<span class="c">#定义时间</span>
<span class="nb">time</span><span class="o">=</span><span class="sb">`</span><span class="nb">date</span> +%Y-%m-%d<span class="se">\ </span>%H:%M:%S<span class="sb">`</span>

<span class="c">#执行成功</span>
<span class="k">function </span>success<span class="o">(){</span>
   <span class="nb">echo</span> <span class="s2">"success"</span>
<span class="o">}</span>

<span class="c">#执行失败</span>
<span class="k">function </span>failure<span class="o">(){</span>
   <span class="nb">echo</span> <span class="s2">"failure"</span>
<span class="o">}</span>

<span class="c">#默认执行</span>
<span class="k">function </span>default<span class="o">(){</span>

  <span class="nb">cd</span> ./_site

<span class="nb">cat</span> <span class="o">&lt;&lt;</span><span class="no">EOF</span><span class="sh"> &gt;&gt; README.md
| 部署状态 | 集成结果                               | 参考值                              |
| -------- | -------------------------------------- | ----------------------------------- |
| 完成时间 | </span><span class="nv">$time</span><span class="sh">                                  | yyyy-mm-dd hh:mm:ss                 |
| 部署环境 | </span><span class="nv">$TRAVIS_OS_NAME</span><span class="sh"> + </span><span class="nv">$TRAVIS_NODE_VERSION</span><span class="sh"> | window </span><span class="se">\|</span><span class="sh"> linux + stable            |
| 部署类型 | </span><span class="nv">$TRAVIS_EVENT_TYPE</span><span class="sh">                     | push </span><span class="se">\|</span><span class="sh"> pull_request </span><span class="se">\|</span><span class="sh"> api </span><span class="se">\|</span><span class="sh"> cron |
| 启用Sudo | </span><span class="nv">$TRAVIS_SUDO</span><span class="sh">                           | false </span><span class="se">\|</span><span class="sh"> true                       |
| 仓库地址 | </span><span class="nv">$TRAVIS_REPO_SLUG</span><span class="sh">                      | owner_name/repo_name                |
| 提交分支 | </span><span class="nv">$TRAVIS_COMMIT</span><span class="sh">                         | hash 16位                           |
| 提交信息 | </span><span class="nv">$TRAVIS_COMMIT_MESSAGE</span><span class="sh">                 |
| Job ID   | </span><span class="nv">$TRAVIS_JOB_ID</span><span class="sh">                         |
| Job NUM  | </span><span class="nv">$TRAVIS_JOB_NUMBER</span><span class="sh">                     |
</span><span class="no">EOF

</span>  git init
  git add <span class="nt">--all</span> <span class="nb">.</span>
  git commit <span class="nt">-m</span> <span class="s2">"Update Blog By TravisCI With Build </span><span class="nv">$TRAVIS_BUILD_NUMBER</span><span class="s2">"</span>
  <span class="c"># Github Pages</span>
  git push <span class="nt">--force</span> <span class="nt">--quiet</span> <span class="s2">"https://</span><span class="k">${</span><span class="nv">REPO_TOKEN</span><span class="k">}</span><span class="s2">@</span><span class="k">${</span><span class="nv">GH_REF</span><span class="k">}</span><span class="s2">"</span> master:master

<span class="o">}</span>

<span class="k">case</span> <span class="nv">$1</span> <span class="k">in</span>
    <span class="s2">"success"</span><span class="p">)</span>
	     success
       <span class="p">;;</span>
    <span class="s2">"failure"</span><span class="p">)</span>
	     failure
	     <span class="p">;;</span>
	         <span class="k">*</span><span class="p">)</span>
       default
<span class="k">esac</span>
</pre></td></tr></tbody></table></code></pre></div></div>

<p>其中我们需要在TravisCI中设置一个环境变量<code class="language-plaintext highlighter-rouge">REPO_TOKEN</code></p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">REPO_TOKEN</code>指的是Github下创建的具有仓库写权限的<code class="language-plaintext highlighter-rouge">Token</code>，点击<a href="https://github.com/settings/tokens/new">此处链接</a>快速创建<code class="language-plaintext highlighter-rouge">Token</code></li>
</ul>

<p><img src="/img/post/20190405/setGithubToken.png" alt="创建Github-Token" /></p>

<p><img src="/img/post/20190405/setCIENV.png" alt="设置CI环境变量" /></p>

<p>然后去Github仓库设置中，选择master分支部署，部署成功后应该是能访问地址<code class="language-plaintext highlighter-rouge">你的用户名.github.io</code>，此处我的访问地址为<code class="language-plaintext highlighter-rouge">mapoio.github.io</code></p>
<blockquote>
  <p>注意：如果没有maste分支，请先检查TravisCI是否成功执行，成功执行后应该是会直接推送静态页面到master分支。</p>
</blockquote>

<p><img src="/img/post/20190405/github-pages.png" alt="设置域名访问" /></p>

<h3 id="部署到coding-pages">部署到Coding Pages</h3>
<p>部署到Coding上的教程也比较简单</p>
<ol>
  <li>在Coding上创建一个<code class="language-plaintext highlighter-rouge">你的用户名</code>的仓库，此处我的仓库名为<code class="language-plaintext highlighter-rouge">sport</code>，不要添加任何东西，直接下一步</li>
  <li>创建一个具有仓库写权限的<code class="language-plaintext highlighter-rouge">访问令牌</code>，点击<a href="https://coding.net/user/account/setting/tokens/new">此处链接</a>直接创建<img src="/img/post/20190405/coding-token.png" alt="创建Coding-Token" /></li>
  <li>修改部署脚本，添加如下内容</li>
</ol>

<div class="language-yml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="rouge-code"><pre><span class="c1"># .travis.yml</span>
<span class="nn">...</span>
<span class="na">env</span><span class="pi">:</span>
 <span class="na">global</span><span class="pi">:</span>
   <span class="c1"># 修改为自己Github用户名</span>
   <span class="pi">-</span> <span class="na">GH_USER_NAME</span><span class="pi">:</span> <span class="s">mapoio</span>
   <span class="c1"># 修改为自己Github仓库地址</span>
   <span class="pi">-</span> <span class="na">GH_REF</span><span class="pi">:</span> <span class="s">github.com/mapoio/mapoio.github.io.git</span>
   <span class="c1"># 修改为自己Coding用户名</span>
   <span class="pi">-</span> <span class="na">CODING_USER_NAME</span><span class="pi">:</span> <span class="s">sport</span>
   <span class="c1"># 修改为自己Coding仓库地址</span>
   <span class="pi">-</span> <span class="na">CODING_REF</span><span class="pi">:</span> <span class="s">git.coding.net/sport/sport.git</span>
</pre></td></tr></tbody></table></code></pre></div></div>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="rouge-code"><pre><span class="c"># _travis.sh</span>
...
  git init
  git add <span class="nt">--all</span> <span class="nb">.</span>
  git commit <span class="nt">-m</span> <span class="s2">"Update Blog By TravisCI With Build </span><span class="nv">$TRAVIS_BUILD_NUMBER</span><span class="s2">"</span>
  <span class="c"># Github Pages</span>
  git push <span class="nt">--force</span> <span class="nt">--quiet</span> <span class="s2">"https://</span><span class="k">${</span><span class="nv">REPO_TOKEN</span><span class="k">}</span><span class="s2">@</span><span class="k">${</span><span class="nv">GH_REF</span><span class="k">}</span><span class="s2">"</span> master:master
  <span class="c"># Coding Pages</span>
  git push <span class="nt">--force</span> <span class="nt">--quiet</span> <span class="s2">"https://</span><span class="k">${</span><span class="nv">CODING_USER_NAME</span><span class="k">}</span><span class="s2">:</span><span class="k">${</span><span class="nv">CODE_TOKEN</span><span class="k">}</span><span class="s2">@</span><span class="k">${</span><span class="nv">CODING_REF</span><span class="k">}</span><span class="s2">"</span> master:master

<span class="o">}</span>

<span class="k">case</span> <span class="nv">$1</span> <span class="k">in</span>
    <span class="s2">"success"</span><span class="p">)</span>
	     success
       <span class="p">;;</span>
    <span class="s2">"failure"</span><span class="p">)</span>
	     failure
	     <span class="p">;;</span>
	         <span class="k">*</span><span class="p">)</span>
       default
<span class="k">esac</span>
...
</pre></td></tr></tbody></table></code></pre></div></div>

<p>此处新添加了一个环境变量<code class="language-plaintext highlighter-rouge">CODE_TOKEN</code>，直接将我们创建的Coding的授权令牌新增到TravisCI中就好了</p>

<p><img src="/img/post/20190405/setCIENV.png" alt="设置CI环境变量" /></p>

<ul>
  <li>开启Coding的Pages服务</li>
</ul>

<blockquote>
  <p>注意：一定要运行一次成功的CI任务后，才能开启Pages服务，如果无法运行Pages服务或者是没有成功把编译后的静态文件推送到Coding的master分支上，则需要检查CI配置和运行情况。</p>
</blockquote>

<p><img src="/img/post/20190405/coding-pages.png" alt="开启Coding的Pages" /></p>

<h3 id="dns分流">DNS分流</h3>
<blockquote>
  <p>DNS分流的作用主要是，在国内国外不同地区访问可以解析不同的CNAME地址，这样就实现了国内访问使用Coding的服务，国外访问就是用Github的服务</p>
</blockquote>

<p>此处使用阿里云解析作为例子，直接使用智能解析即可，创建两条CNAME解析记录</p>

<table>
  <thead>
    <tr>
      <th>记录类型</th>
      <th>解析线路</th>
      <th>记录值</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>CNAME</td>
      <td>默认</td>
      <td>sport.coding.me</td>
    </tr>
    <tr>
      <td>CNAME</td>
      <td>国外</td>
      <td>mapoio.github.io</td>
    </tr>
  </tbody>
</table>

<p><img src="/img/post/20190405/cname.png" alt="设置阿里云CNAME解析" /></p>

<p>然后分别在他们的Pages服务中添加域名解析即可<br />
添加域名后还需要修改在Github上的<code class="language-plaintext highlighter-rouge">source</code>分支上的<code class="language-plaintext highlighter-rouge">CNAME</code>文件，里面直接写入你解析好的域名地址，此处我的地址为<code class="language-plaintext highlighter-rouge">mapo.io</code>。</p>

<h3 id="https设置">HTTPS设置</h3>
<blockquote>
  <p>如果要开启HTTPS的话会有点麻烦，这里介绍一下，如何同时开启HTTPS访问<br />
重要：下面的步骤顺序很关键，打乱顺序将可能导致无法开启HTTPS访问</p>
</blockquote>

<ol>
  <li>前往阿里云解析<strong>暂停</strong>国外路线</li>
  <li>前往Coding申请HTTPS证书</li>
  <li>前往阿里云解析<strong>启用</strong>国外路线</li>
  <li>前往Github申请HTTPS证书</li>
</ol>

<p>整个过程就是这样，之所以不能调换顺序，是因为Coding的Pages服务器和Let’s Encrypt的服务器都在国外，要想通过Let’s Encrypt证书颁发检验只能一个一个的颁发。</p>

<h2 id="注意事项以及部分问题的解决办法">注意事项以及部分问题的解决办法</h2>
<ol>
  <li>上传分支后，只能推送一次就再也没有反应了或者第一次CI部署成功后，文件都变样了
    <blockquote>
      <p>请检查源代码分支是否在<code class="language-plaintext highlighter-rouge">source</code>分支上，或者检查部署分支与写作的分支是否不再同一条分支上。</p>
    </blockquote>
  </li>
  <li>提示HTTPS证书过期了怎么办
    <blockquote>
      <p>通常情况下都是Coding上的服务器证书过期，此时只要重复上文中<strong>HTTPS设置</strong>的前两步即可重新申请一个有效证书，Github会自动续期证书。Coding证书每三个月需要手工维护一次</p>
    </blockquote>
  </li>
  <li>如何得知部署是否成功
    <blockquote>
      <p>首先检查CI状态是否为<code class="language-plaintext highlighter-rouge">SUCCESS</code>，其次可以前往Github或者Coding的主页上，看<code class="language-plaintext highlighter-rouge">README.md</code>文件，上面会自动列出本次部署的最新情况</p>
    </blockquote>
  </li>
  <li>Pages分支最好Github和Coding保持一致，不要错误的将编译后的及静态文件推送到写作分支上</li>
</ol>

<h2 id="参考资料">参考资料</h2>
<ul>
  <li><a href="https://github.com/gitalk/gitalk">Gitalk设置指南</a></li>
  <li><a href="https://github.com/Huxpro/huxpro.github.io">Hux</a></li>
  <li><a href="https://withdewhua.space/2018/09/18/Blog_3/">将JEKYLL博客同时托管在GITHUB PAGES和CODING PAGES | BLOG折腾小记（3）</a></li>
</ul>

                <!-- copyright start -->
                <div>
                    
  <ul class="post-copyright">
    <li class="post-copyright-author">
      <strong>本文作者：</strong>
      Mapo
    </li>
    <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://mapo.io/2019/04/06/how-to-depoly-jekyll/" title="同时部署Jekyll到Github和Coding的Pages服务上">https://mapo.io/2019/04/06/how-to-depoly-jekyll/</a>
    </li>
    <li class="post-copyright-license">
      <strong>版权声明： </strong>
      本博客所有文章除特别声明外，均采用
      <a
        href="https://creativecommons.org/licenses/by-nc-sa/3.0/"
        rel="external nofollow"
        target="_blank"
      >
        CC BY-NC-SA 3.0
      </a>
      许可协议。转载请注明出处！
    </li>
  </ul>


                </div>
                <!-- copyright end -->
                <hr style="visibility: hidden;">
                <ul class="pager">
                    
                    <li class="previous">
                        <a href="/2019/04/05/hello-2019/" data-toggle="tooltip" data-placement="top" title="开始写博客">
                        Previous<br>
                        <span>开始写博客</span>
                        </a>
                    </li>
                    
                    
                </ul>
                <hr style="visibility: hidden;">

                

                

                
                <!-- Gitalk 评论框 start -->
                <div id="gitalk-container"></div>
                <!-- Gitalk 评论框 end -->
                
                
            </div>  

    <!-- Side Catalog Container -->
        
            <div class="
                col-lg-2 col-lg-offset-0
                visible-lg-block
                sidebar-container
                catalog-container">
                <div class="side-catalog">
                    <hr class="hidden-sm hidden-xs">
                    <h5>
                        <a class="catalog-toggle" href="#">CATALOG</a>
                    </h5>
                    <ul class="catalog-body"></ul>
                </div>
            </div>
        

    <!-- Sidebar Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                


<section>
    
        <hr class="hidden-sm hidden-xs">
    
    <h5><a href="/archive/">FEATURED TAGS</a></h5>
    <div class="tags">
        
        
        
        </a>
        
        
                <a data-sort="0000" 
                    href="/archive/?tag=%E8%AE%B0%E5%BD%95"
                    title="记录"
                    rel="2">记录
    </div>
</section>


                <!-- Friends Blog -->
                
<hr>
<h5>FRIENDS</h5>
<ul class="list-inline">
  
  <li><a href="https://blog.woodcoding.com">WoodCoding</a></li>
  
</ul>

            </div>
        </div>
    </div>
</article>

<!-- add support for mathjax by voleking-->








<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>


<!-- gitalk 公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
    async("//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js",function(){
        var gitalk_clientID = "fa4577cfb667bd719581";
        var gitalk_clientSecret = "634c2e561edfa65568dfee8dc12dcc9d29c106b3";
        var gitalk_repo = "gitalk";
        var gitalk_owner = "mapoio";
        var gitalk_admin = "mapoio".split(',');
        var gittalk_identifier = "/2019/04/06/how-to-depoly-jekyll";
        var gitalk = new Gitalk({
            clientID: gitalk_clientID,
            clientSecret: gitalk_clientSecret,
            repo: gitalk_repo,
            owner: gitalk_owner,
            admin: gitalk_admin,
            id: gittalk_identifier,      // Ensure uniqueness and length less than 50
            distractionFreeMode: true  // Facebook-like distraction free mode
        })

        gitalk.render('gitalk-container')
    })
</script>
<!-- gitalk 公共JS代码 end -->


<!-- anchor-js, Doc:http://bryanbraun.github.io/anchorjs/ -->
<script>
    async("//cdnjs.cloudflare.com/ajax/libs/anchor-js/1.1.1/anchor.min.js",function(){
        anchors.options = {
          visible: 'always',
          placement: 'right',
          icon: '#'
        };
        anchors.add().remove('.intro-header h1').remove('.subheading').remove('.sidebar-container h5');
    })
</script>
<style>
    /* place left on bigger screen */
    @media all and (min-width: 800px) {
        .anchorjs-link{
            position: absolute;
            left: -0.75em;
            font-size: 1.1em;
            margin-top : -0.1em;
        }
    }
</style>



    <!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <!-- SNS Link -->
                


<ul class="list-inline text-center">


  
  <li>
    <a href="/feed.xml">
      <span class="fa-stack fa-lg">
        <i class="fa fa-circle fa-stack-2x"></i>
        <i class="fa fa-rss fa-stack-1x fa-inverse"></i>
      </span>
    </a>
  </li>
  
  
  <li>
    <a href="https://twitter.com/isheng">
      <span class="fa-stack fa-lg">
        <i class="fa fa-circle fa-stack-2x"></i>
        <i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
      </span>
    </a>
  </li>
  
  
  <li>
    <a target="_blank" href="https://www.zhihu.com/people/mapoio">
      <span class="fa-stack fa-lg">
        <i class="fa fa-circle fa-stack-2x"></i>
        <i class="fa  fa-stack-1x fa-inverse">知</i>
      </span>
    </a>
  </li>
  
  
  
  
  <li>
    <a target="_blank" href="https://github.com/mapoio">
      <span class="fa-stack fa-lg">
        <i class="fa fa-circle fa-stack-2x"></i>
        <i class="fa fa-github fa-stack-1x fa-inverse"></i>
      </span>
    </a>
  </li>
  
  
</ul>

                <p class="copyright text-muted">
                    Copyright &copy; Mapo 2020
                    <br>
                    Powered by <a href="https://jekyllrb.com">Jekyll</a> | Designed By <a href="http://huangxuan.me">Hux</a>
                    <!-- <iframe
                        style="margin-left: 2px; margin-bottom:-5px;"
                        frameborder="0" scrolling="0" width="100px" height="20px"
                        src="https://ghbtns.com/github-btn.html?user=huxpro&repo=huxpro.github.io&type=star&count=true" >
                    </iframe> -->
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js "></script>

<!-- Bootstrap Core JavaScript -->
<!-- Currently, only navbar scroll-down effect at desktop still depends on this -->
<script src="/js/bootstrap.min.js "></script>

<!-- Custom Theme JavaScript -->
<script src="/js/hux-blog.min.js "></script>

<!-- Service Worker -->

<script src="/js/snackbar.js "></script>
<script src="/js/sw-registration.js "></script>


<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!--
     Because of the native support for backtick-style fenced code blocks
     right within the Markdown is landed in Github Pages,
     From V1.6, There is no need for Highlight.js,
     so Huxblog drops it officially.

     - https://github.com/blog/2100-github-pages-now-faster-and-simpler-with-jekyll-3-0
     - https://help.github.com/articles/creating-and-highlighting-code-blocks/
     - https://github.com/jneen/rouge/wiki/list-of-supported-languages-and-lexers
-->
<!--
    <script>
        async("http://cdn.bootcss.com/highlight.js/8.6/highlight.min.js", function(){
            hljs.initHighlightingOnLoad();
        })
    </script>
    <link href="http://cdn.bootcss.com/highlight.js/8.6/styles/github.min.css" rel="stylesheet">
-->





<!--fastClick.js -->
<script>
    async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>


<!-- Google Analytics -->

<script>
    // dynamic User by Hux
    var _gaId = 'UA-137551468-1';
    var _gaDomain = 'mapo.io';

    // Originial
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', _gaId, _gaDomain);
    ga('send', 'pageview');
</script>



<!-- Baidu Tongji -->



<!-- Side Catalog -->

<script type="text/javascript">
    function generateCatalog (selector) {

        // interop with multilangual 
        if ('' == 'true') {
            _containerSelector = 'div.post-container.active'
        } else {
            _containerSelector = 'div.post-container'
        }

        // init
        var P = $(_containerSelector),a,n,t,l,i,c;
        a = P.find('h1,h2,h3,h4,h5,h6');

        // clean
        $(selector).html('')

        // appending
        a.each(function () {
            n = $(this).prop('tagName').toLowerCase();
            i = "#"+$(this).prop('id');
            t = $(this).text();
            c = $('<a href="'+i+'" rel="nofollow">'+t+'</a>');
            l = $('<li class="'+n+'_nav"></li>').append(c);
            $(selector).append(l);
        });
        return true;
    }

    generateCatalog(".catalog-body");

    // toggle side catalog
    $(".catalog-toggle").click((function(e){
        e.preventDefault();
        $('.side-catalog').toggleClass("fold")
    }))

    /*
     * Doc: https://github.com/davist11/jQuery-One-Page-Nav
     * Fork by Hux to support padding
     */
    async("/js/jquery.nav.js", function () {
        $('.catalog-body').onePageNav({
            currentClass: "active",
            changeHash: !1,
            easing: "swing",
            filter: "",
            scrollSpeed: 700,
            scrollOffset: 0,
            scrollThreshold: .2,
            begin: null,
            end: null,
            scrollChange: null,
            padding: 80
        });
    });
</script>



<!-- Multi-Lingual -->




<!-- Image to hack wechat -->
<img src="/img/icon_wechat.png" width="0" height="0" />
<!-- Migrate from head to bottom, no longer block render and still work -->

</body>

</html>
